package WaitNotify.demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-12-25
 * Time: 14:03
 */
public class GuardedObject {

    private Object response;

    //获取结果
    public Object get() throws InterruptedException {
        synchronized (this) {
            while (response==null) {
                this.wait();
            }
            return this.response;
        }
    }

    //产生结果
    public void complete(Object response) {
        synchronized (this) {
            this.response = response;
            this.notifyAll();
        }
    }

}
